package com.eairlv.share.auto.controller;

import com.eairlv.share.auto.entity.Result;
import com.eairlv.share.auto.entity.bo.ShareTableDbForm;
import com.eairlv.share.auto.entity.bo.ShareTableForm;
import com.eairlv.share.auto.entity.bo.ShareTableResultForm;
import com.eairlv.share.auto.entity.bo.ShareTableSearchForm;
import com.eairlv.share.auto.entity.bo.TemplateTableForm;
import com.eairlv.share.auto.entity.vo.ShareTableDbInfoVO;
import com.eairlv.share.auto.entity.vo.ShareTableDbVO;
import com.eairlv.share.auto.entity.vo.ShareTableRecordVO;
import com.eairlv.share.auto.entity.vo.ShareTableVO;
import com.eairlv.share.auto.service.ShareService;
import com.eairlv.share.auto.service.ShareTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author eairlv
 * @description
 * @date 14:45 2020/1/13
 */
@Slf4j
@Api(tags = "分片规则接口")
@RestController
@RequestMapping("/share/rule")
public class ShareTableController {

    @Autowired
    ShareTableService shareTableService;

    @ApiOperation("新增或修改分片规则")
    @PostMapping
    public Result<Integer> addShareRule(@RequestBody ShareTableForm shareTableForm){
        return shareTableService.addShareRule(shareTableForm);
    }

    @ApiOperation("删除分片规则")
    @DeleteMapping("/{id}")
    public Result<Integer> deleteShareRule(@PathVariable Integer id){
        return shareTableService.deleteShareRule(id);
    }

    @ApiOperation("查询分片规则")
    @GetMapping
    public Result<List<ShareTableVO>> getShareRule(ShareTableSearchForm shareTableSearchForm){
        return shareTableService.getShareRule(shareTableSearchForm);
    }
}
